﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using OpenViewer.Protocol;
using ThirdLife.UI.WinForms.Modules;

//UIModuleServices.Instance.Metaverse.LoginWithGivenInfo( )

namespace ThirdLife.UI.WinForms.Controls
{
  public partial class TLChatArea : UserControl, IDockableUserControlView
  {
    private ChatAreaUIModule _chatModule;

    public TLChatArea()
    {
      InitializeComponent();
    }

    public TLChatArea(ChatAreaUIModule module)
    {
      _chatModule = module;
      InitializeComponent();
    }

    public void SetupView()
    {
    }

    public void DestroyView()
    {

    }

    public int ControlId
    {
      get { return 3; }
    }

    public object Control
    {
      get { return this; }
    }

    private void textBox1_TextChanged(object sender, EventArgs e)
    {
        //Start typing animation
    }

    private void btnSay_Click(object sender, EventArgs e)
    {
        string chatText = textBox1.Text;
        textBox1.Clear();
       
        //this is where you use module services to communicate your chat
        _chatModule.ModuleServices.Communication.Chat(chatText);
    }

    public void AddNewMessageFromAvatar(string name, string message)
    {
        name = UIModuleServices.Instance.Metaverse.DefaultName.ToString();
        richTextBox1.AppendText("\r\n" + name + ":" + message);
    }
      
    private void listAvatars_SelectedIndexChanged(object sender, EventArgs e)
    {
       // AddAvatar();
    }

  
      /* The following code to be placed in the appropriate area of UI Modules function
      
       * Add avatar to listAvatars list view box
 
    public void AddAvatar(Avatar av)
    {

        if (av == null) return;
        string name = av.Name;

        if (lvwObjects.Items.ContainsKey(name)) return;

        ListViewItem item = lvwObjects.Items.Add(name, name, string.Empty);
        if (name == client.Self.Name) item.Font = new Font(item.Font, FontStyle.Bold);
        item.Tag = av;
    }
    private void Objects_OnNewAvatar(Simulator simulator, Avatar avatar, ulong regionHandle, ushort timeDilation)
    {
        /*
        if (!avatars.ContainsKey(avatar.LocalID))
            avatars.Add(avatar.LocalID, avatar);

        BeginInvoke(new OnAddAvatar(AddAvatar), new object[] { avatar });
         
    }
      */

  }
}
